/*
 * AutoCompleteServlet.java
 *
 * Created on June 20, 2005, 7:24 PM
 */

package com.cdpark.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cdpark.service.UserService;



/**
 *
 * @author nate
 * @version
 */
public class AutoCompleteServlet extends HttpServlet {

	private UserService userService = new UserService();
	
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        
    	request.setCharacterEncoding("GB2312");
        response.setCharacterEncoding("GB2312");
        
        response.setHeader("Charset","UTF-8");
        response.setHeader("Content-Type","text/html");
        
        String searchCDSelect = request.getParameter("searchCDSelect");
        String searchCondition = request.getParameter("searchCondition");
        PrintWriter out = response.getWriter();
        response.setHeader("Cache-Control", "no-cache");
       
        List conditionList = userService.searchConditionAutoComplete(searchCDSelect,searchCondition);

        StringBuffer conditionStr = new StringBuffer();
        
        if(conditionList.size() != 0) {
        	conditionStr.append(conditionList.get(0));
        	for(int i = 1, n = conditionList.size(); i < n; i ++) {
        		conditionStr.append("," + conditionList.get(i));
        	}
        }
        
        out.println(conditionStr.toString());
        out.flush();
        out.close();
           

    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        doGet(request, response);
    }
        
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
}
